package com.gravata.enigma;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;

import com.gravata.enigma.activities.TelaInicial;
import com.gravata.enigma.model.Bouquet;
import com.gravata.enigma.model.Service;

public class ReloadServicesFromReceiver implements OnTaskCompleted {
	private ReloadDataListener dataListener;
	private Context context;

	public ReloadServicesFromReceiver(Context context, ReloadDataListener dataListener) {
		this.dataListener=dataListener;
		this.context=context;
	}

	public void getData(){
		new LoadFromReceiver(context,this).execute();
	}

	@Override
	public void onTaskCompleted() {

		List<Service> tmpServicos= TelaInicial.repositorioService.listar(TelaInicial.profile);
		List<Bouquet> tmpBouquet=TelaInicial.repositorioBouquets.listar(TelaInicial.profile);


		if(tmpServicos.size()>0)
			TelaInicial.servicos=(ArrayList<Service>) tmpServicos;
		else
			TelaInicial.servicos=new ArrayList<Service>();

		if(tmpBouquet.size()>0)
			TelaInicial.bouquets=(ArrayList<Bouquet>) tmpBouquet;
		else
			TelaInicial.bouquets=new ArrayList<Bouquet>();


		TelaInicial.sateliteComboAdapter.setData(TelaInicial.repositorioSatelite.listar(TelaInicial.profile));

		dataListener.onReloadData();

	}
}
